<template>
	<el-dialog v-model="control.visible" title="提示" width="500" :before-close="public_close">

		<section>
			<span>请确认是否删除该节点？</span>
		</section>
		
		<template #footer>
			<div class="dialog-footer">
				<el-button @click="public_close">取消</el-button>
				<el-button type="primary" @click="control_click">
					确认
				</el-button>
			</div>
		</template>
	</el-dialog>
</template>
<script>
	import config from "@/config/config.js";
	import xcHttpUtils from '@/library/xcore/js/XcHttpUtils.js';
	import xcViewUtils from '@/library/xcore/js/XcViewUtils.js';
	import {
		xsStringUtils,
		xsDateUtils,
		xsArrayUtils
	} from 'xstack-for-javascript';

	export default {
		props: {
			fstatusList: {
				type: Array,
				default: []
			},
			flogicList: {
				type: Array,
				default: []
			},
		},
		watch: {
			'fstatusList': {
				handler(newVal, oldVal) {
					let that = this;
					that.public_show();
				},
			},
		},
		data() {
			return {
				config: config,
				xsStringUtils: xsStringUtils,
				xsDateUtils: xsDateUtils,
				xsArrayUtils: xsArrayUtils,
				sp: {
					clickFlogicId: null,
					callbackFunc: null
				},
				sr: {
					parentFlogicIndexes: [],
					childFlogicIndexes: [],
				},
				control: {
					visible: false
				}
			}
		},
		created() {
			let that = this;
			that.xinit();
		},
		methods: {
			xinit() {
				let that = this;

			},
			public_show(clickFlogicId, callbackFunc) {
				let that = this;
				
				that.sp.clickFlogicId = clickFlogicId;
				that.sp.callbackFunc = callbackFunc;
				
				let clickFlogicIndex = xsArrayUtils.indexesOfByObjectKey(that.flogicList, 'id', clickFlogicId);
				if (xsArrayUtils.contains(["all", "other"], that.flogicList[clickFlogicIndex]["logictype"])) {
					xcViewUtils.message_error("此节点为默认分支节点，无法删除",function(){
						that.public_close();
					});
				}else{
					that.control.visible = true;
				}
			},
			public_reset() {
				let that = this;
				that.public_show();
			},
			public_close() {
				let that = this;
				that.control.visible = false;
			},
			control_click() {
				let that = this;
				let clickFlogicIndex = xsArrayUtils.indexesOfByObjectKey(that.flogicList, 'id', that.sp.clickFlogicId);
				
				// all -> other if only one node
				//console.log('----->',that.flogicList,clickFlogicIndex);return;
				let logicIndexes = xsArrayUtils.indexesOfByObjectKey(that.flogicList, "flowfstatus_id", that.flogicList[clickFlogicIndex]["flowfstatus_id"]);
				if(xsArrayUtils.length(logicIndexes)==1){
					that.flogicList[logicIndexes[0]]["logictype"] = "all";
				}
				
				// delete current logic
				xsArrayUtils.remove(that.flogicList, clickFlogicIndex , 1);
				
				that.control.visible = false;
				that.sp.callbackFunc();
			}
		}
	}
</script>

<style lang="scss">
	.xp-content {
		padding-bottom: $uni-spacing-col-base;
	}
</style>